<template>
    <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
import resize from '../../../assets/js/charts/resize'
export default {
    mixins: [resize],
    props: {
        pieOption: {},
        className: {
            type: String,
            default: 'chart'
        },
        id: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '200px'
        },
        height: {
            type: String,
            default: '200px'
        }
    },
    data() {
        return {
            chart: null
        }
    },
    mounted() {
        this.$nextTick(()=>{
            this.initChart()
        });
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            var myColor = this.pieOption.myColor;
            var pieData = this.pieOption.pieData;
            this.chart = echarts.init(document.getElementById(this.id));
            this.chart.setOption({
                tooltip: {
                    trigger: 'item',
                    padding:[12,18],
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                series: [
                    {
                        name: '资产情况',
                        type: 'pie',
                        avoidLabelOverlap: true,   //是否启用防止标签重叠策略
                        hoverAnimation: false,//取消hover放大效果
                        radius: '50%',//饼图大小
                        center: ['40%', '60%'],//饼图相对于画布中心点的位置
                        color: myColor,
                        labelLine: {
                            normal: {
                                length: 20,//折线第一节的长度
                                length2: 120,//折线第二节的长度
                                lineStyle: {
                                    color: '#A0A0A0'
                                }
                            }

                        },
                        label: {
                            normal: {
                                formatter: "{b} : {c}    {d}%\n\n",
                                //注意：末尾加\n换行，不然文字和引线会叠在一起
                                borderWidth: 16,
                                borderRadius: 4,
                                padding: [0, -120],//标注文字在引线上的左右偏移量
                                color: '#000',//标注文字全部都用黑色
                       
                            }
                        },
                        data: pieData
                    }
                ]
            })
        }
    }
}
</script>
